package com.neuedu.yyzx.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ResUtils {
    /**
     * 将对象转换成json数据并发送给 客户端
     * @param response
     * @param object
     * @throws IOException
     */
    public  static void writeJSON(HttpServletResponse response , Object object) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        //res---json 数
        String jsonRes = objectMapper.writeValueAsString(object);
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(jsonRes);
        response.flushBuffer();
    }
}
